package com.cdpark.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cdpark.service.CDService;
import com.cdpark.vo.CDVO;

public class ToolTipServlet extends HttpServlet {
    
   private CDService cdService = new CDService();

    public void init(ServletConfig config) throws ServletException {
       
    }
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        Long targetCDID = Long.parseLong(request.getParameter("key"));
       
        CDVO targetCDVO = cdService.searchByCDID(targetCDID);
        
        
        response.setContentType("text/xml;charset=gb2312");
        response.setHeader("Cache-Control", "no-cache");
   //     response.setHeader("Charset","UTF-8");
        
        PrintWriter out = response.getWriter();

        out.println("<?xml version='1.0' encoding='"+"gb2312"+"' ?>"); 
        out.println("<response>");
        out.println("<company>" + targetCDVO.getCompany() + "</company>");
        out.println("<language>" + targetCDVO.getLanguage() + "</language>");
        out.println("<price>" + targetCDVO.getPrice() + "</price>");
        out.println("<discount>" + targetCDVO.getDiscount() + "</discount>");
        out.println("<cdtype>" + targetCDVO.getCDTypeVO().getCdtypeName() + "</cdtype>");
        out.println("</response>");
        out.close();
    }
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        doGet(request, response);
    }
        
}